package alpha.com.google.code.mechanic.janitor.model;

import java.io.File;

/**
 * The class is to initialise the default file path that the Janitor uses
 * to store its files.
 * 
 * Last_edited: Nov 27, 2014
 * 
 * @History
 * 1. Change the method initDefSysFilePath() from protected to public.
 * @author jingjiejiang
 * @Edited Oct 7, 2014
 * 
 * 2. Change the methods: initDefSysFilePath() and initCtxFileDir().
 * @author jingjiejiang
 * @edited Nov 27, 2014
 * 1) Use File.separator instead of using hard code path separator to avoid
 * judging OS typs.
 * 
 * @author jingjiejiang
 * @since Jul 29, 2014
 *
 */
public class DefaultSysFilePath {

  public static final String OSX_ID = "OS X";
  public static final String LINUX_ID = "Linux";
  public static final String WINDOWS_ID = "Windows";
  
  private String defaultSysFilePath;
  
  public DefaultSysFilePath () {
    initDefSysFilePath();
  }
  
  public String getDefaultSysFilePath() {
    return defaultSysFilePath;
  }

  /**
   * Get the home directory of the OS.
   * @return
   */
  public String getHomeDir() {
    
    return System.getProperty("user.home");
  }
  
  /**
   * Distinguish home directories from different OS system.
   *
   * @return
   */
  public String getOSID () {
    
    String id = "";
    String homedir = getHomeDir();
    
    if (homedir.startsWith("/Users")) {
      id = OSX_ID;
    }
    else if (homedir.startsWith("/home")) {
      id = LINUX_ID;
    }
    else if (homedir.contains(":\\Users")) {
      id = WINDOWS_ID;
    }
    
    return id;
  }
  
  /**
   * Initialise the normal default directory for the Janitor as
   * (home)/.eclipse/mechanic/ (take OSX and LINUX as an example).
   *
   */
  public void initDefSysFilePath () {
    
    defaultSysFilePath = getHomeDir();
    
//    if (OSX_ID == osid || LINUX_ID == osid) {
//      defaultSysFilePath = defaultSysFilePath + "/.eclipse/mechanic/";
//    }
//    else if (WINDOWS_ID == osid) {
//      defaultSysFilePath = defaultSysFilePath + "\\.eclipse\\mechanic\\";
//    }
    
    defaultSysFilePath = defaultSysFilePath + File.separator + ".eclipse" +
        File.separator + "mechanic" + File.separator;
  }
  
  /**
   * Initialise the default directory for the user defined Contexts in
   * the Janitor.
   *
   */
  public void initCtxFileDir() {
    
    initDefSysFilePath();
//    String osid = getOSID();
//    
//    if (OSX_ID == osid || LINUX_ID == osid) {
//      defaultSysFilePath = defaultSysFilePath + "Contexts/";
//    }
//    else if (WINDOWS_ID == osid) {
//      defaultSysFilePath = defaultSysFilePath + "Contexts\\";
//    }
    defaultSysFilePath = defaultSysFilePath + "Contexts" + File.separator;
  }
  
}
